package org.ucas.faker.common.tech;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.dom4j.Branch;

public class KeywordTree {
	
	public Set<String> branch;
	public Set<String> effect;
	
	public KeywordTree(){
		branch = new HashSet<>();
		effect = new HashSet<>();

		try {
			InputStream is = this.getClass().getClassLoader().getResourceAsStream("magnetic_branch");

			InputStreamReader read = new InputStreamReader(is);// 考虑到编码格式
			BufferedReader featureReader = new BufferedReader(read);
			String lineTxt = null;
			while ((lineTxt = featureReader.readLine()) != null) {
				// System.out.println(lineTxt);
				if(lineTxt.length()>1) branch.add(lineTxt);
				//features.add(lineTxt);
			}
		} catch (Exception e) {
			System.out.println("分支");
			e.printStackTrace();
		}
		
		
		try {
			InputStream is = this.getClass().getClassLoader().getResourceAsStream("magnetic_effect");
			// File file=new File("effect.rule");
			InputStreamReader read = new InputStreamReader(is);// 考虑到编码格式
			BufferedReader featureReader = new BufferedReader(read);
			String lineTxt = null;
			while ((lineTxt = featureReader.readLine()) != null) {
				// System.out.println(lineTxt);
				if(lineTxt.length()>1) effect.add(lineTxt);
			}
			read.close();
		} catch (Exception e) {
			System.out.println("Error reading 功效");
			e.printStackTrace();
		}
		/*
		for(String s:branch){
			System.out.print(s+'\t');
		}
		System.out.println();
		for(String s:effect){
			System.out.print(s+'\t');
		}*/
	}
	
	public void classify(String abstraction,Set<String> bra, Set<String> eff,List<String> words){
		
		for(String s:branch){
			if(abstraction.indexOf(s)>-1) {
				bra.add(s);
				if(words.contains(s)) words.remove(s);
			}
		}
		for(String s:effect){
			if(abstraction.indexOf(s) > -1) {
				eff.add(s);
				if(words.contains(s)) words.remove(s);
			}
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		KeywordTree kt = new KeywordTree();
	
		
		
	}

}
